package com.starinside.wp.repository;

import com.starinside.wp.domain.Children;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * *******************************
 * Created by Tim.
 * form com.matt
 * on 2017/7/13
 * *******************************
 */
@Repository
public interface ChildrenRepository extends JpaRepository<Children, String>, JpaSpecificationExecutor<Children> {
    Children findByCrmClienteleId(String clienteleId);

    Children findByNameAndBirthdayAndAreaId(String name, Date birthday, String areaId);

    List<Children> findByAreaIdAndStatus(String areaId, Integer status);

    List<Children> findByAreaIdAndStatusAndIsDisplayForAdmin(String areaId, Integer status, Boolean isHidden);

    List<Children> findByAreaIdAndIsDisplayForAdmin(String areaId, Boolean isHidden);

    @Query(value = "select c from Children c where c.areaId=:areaId and c.name like CONCAT('%', :name, '%') and c.isDisplayForAdmin = :isHidden")
    List<Children> findByAreaIdAndNameLikeAndIsDisplayForAdmin(@Param("areaId") String areaId, @Param("name") String name, @Param("isHidden") Boolean isHidden);

    List<Children> findByIdIn(String... childrenIds);

    Integer countByAreaIdAndCreatedBetween(String areaId, Date begin, Date end);

    List<Children> findByNameAndAreaId(String childrenName, String areaId);

    List<Children>  findAllByAreaId(String areaId);
}
